<?
//引入所有子系统信息
include_once("../../../common/script/extender_import.php");


//**获取当前板块资料，必然载入，后续很多读取板块数据库的表格，都写成动态的了。
include_once("script/this_plate.php");


//获取板块的设置
include_once("../model/setting.php");


//根据页面数量信息，筛选信息，创造url，供页码,跳转等使用
include_once("script/set_url.php");
?>

<?


//$_price=$_REQUEST['ai_price'];
//if (isset($_price) && is_numeric($_price)) {
//    $_price = number_format((float)$_price, 2);
//} else {
//    // 可以设置默认值或者提示错误
//    $_price = '0.00'; // 或 null / 空字符串，根据业务决定
//}
//
//$_REQUEST['ai_price']=$_price;



$_REQUEST['ai_authur']      = $_SESSION['username'];
$_REQUEST['ai_ip']          = $_SERVER["REMOTE_ADDR"];


//判断这个新增加的分类，是什么层级
if($_REQUEST['ai_parent_nid'] == 'root')
{
    $_REQUEST['ai_category_level'] = 'level01';
}
else
{
    //判断父类是什么层级
    $_parent_category = select($table_prefix.$this_plate['table']['category'],$_REQUEST['ai_parent_nid']);

    if($_parent_category[0]['category_level'] == 'level01')
    {
        echo $_REQUEST['ai_category_level'] = 'level02';
    }
    else
    {
        echo $_REQUEST['ai_category_level'] = 'level03';
    }
}




//这里是设计上传文件的部分：包含图片和附件。视频也应该用这种形式上传
//统一设置一下保存图片的路径
$_uf['path']        = ROOT_PATH_ . "/uploadfiles/".$theme_folder."/";





//上传icon
if (is_uploaded_file($_FILES['icon']['tmp_name']))
{
$_uf['upfile']       = $_FILES['icon'];
$_info               = upload_file($_uf);
$_REQUEST['ai_icon'] = $_info['name'];

    $icon          = $_REQUEST['ai_icon'];


}

//上传Banner
if (is_uploaded_file($_FILES['banner']['tmp_name']))
{
$_uf['upfile']       = $_FILES['banner'];
$_info               = upload_file($_uf);
$_REQUEST['ai_banner'] = $_info['name'];
    $banner        = $_REQUEST['ai_banner'];

}

//上传image1
if (is_uploaded_file($_FILES['image1']['tmp_name']))
{
$_uf['upfile']         = $_FILES['image1'];
$_info                 = upload_file($_uf);
$_REQUEST['ai_image1'] = $_info['name'];
    $destination1  = $_REQUEST['ai_image1'];


}

//上传image2
if (is_uploaded_file($_FILES['image2']['tmp_name']))
{
$_uf['upfile']         = $_FILES['image2'];
$_info                 = upload_file($_uf);
$_REQUEST['ai_image2'] = $_info['name'];
    $destination2  = $_REQUEST['ai_image2'];


}

//上传image3
if (is_uploaded_file($_FILES['image3']['tmp_name']))
{
$_uf['upfile']         = $_FILES['image3'];
$_info                 = upload_file($_uf);
$_REQUEST['ai_image3'] = $_info['name'];
    $destination3  = $_REQUEST['ai_image3'];


}


//上传image4
if (is_uploaded_file($_FILES['image4']['tmp_name']))
{
$_uf['upfile']         = $_FILES['image4'];
$_info                 = upload_file($_uf);
$_REQUEST['ai_image4'] = $_info['name'];
    $destination4  = $_REQUEST['ai_image4'];


}



//上传image5
if (is_uploaded_file($_FILES['image5']['tmp_name']))
{
$_uf['upfile']         = $_FILES['image5'];
$_info                 = upload_file($_uf);
$_REQUEST['ai_image5'] = $_info['name'];
    $destination5  = $_REQUEST['ai_image5'];

}





//上传image6
if (is_uploaded_file($_FILES['image6']['tmp_name']))
{
$_uf['upfile']         = $_FILES['image6'];
$_info                 = upload_file($_uf);
$_REQUEST['ai_image6'] = $_info['name'];
    $destination6  = $_REQUEST['ai_image6'];

}


//上传image7
if (is_uploaded_file($_FILES['image7']['tmp_name']))
{
$_uf['upfile']         = $_FILES['image7'];
$_info                 = upload_file($_uf);
$_REQUEST['ai_image7'] = $_info['name'];
    $destination7  = $_REQUEST['ai_image7'];

}


//上传image8
if (is_uploaded_file($_FILES['image8']['tmp_name']))
{
$_uf['upfile']         = $_FILES['image8'];
$_info                 = upload_file($_uf);
$_REQUEST['ai_image8'] = $_info['name'];
    $destination8  = $_REQUEST['ai_image8'];

}


//上传image9
if (is_uploaded_file($_FILES['image9']['tmp_name']))
{
$_uf['upfile'] = $_FILES['image9'];
$_info                 = upload_file($_uf);
$_REQUEST['ai_image9'] = $_info['name'];
    $destination9  = $_REQUEST['ai_image9'];

}


//上传image10
if (is_uploaded_file($_FILES['image10']['tmp_name'])) {
$_uf['upfile']          = $_FILES['image10'];
$_info                  = upload_file($_uf);
$_REQUEST['ai_image10'] = $_info['name'];
    $destination10 = $_REQUEST['ai_image10'];
}



//上传备用图片
if (is_uploaded_file($_FILES['extend_img']['tmp_name'])) {
$_uf['upfile']             = $_FILES['extend_img'];
$_info                     = upload_file($_uf);
$_REQUEST['ai_extend_img'] = $_info['name'];

}


//上传附件
if (is_uploaded_file($_FILES['attachment']['tmp_name'])) {
$_uf["allowExt"] = array('jpeg',
'jpg',
'png',
'gif',
'rar',
'zip',
'7zip',
'exe',
'msi',
'txt',
'doc',
'xlsx',
'pptx',
'pdf',
    'webp');
$_uf['upfile']             = $_FILES['attachment'];
$_info                     = upload_file($_uf);
$_REQUEST['ai_attachment'] = $_info['name'];

}

?>


<?php
$sql=insert_data($table_prefix.$this_plate['table']['category'],$_REQUEST);
$query = execute_query($sql);





//******************************************
//判断是否插入成功，然后把图片从temp目录移动出来
//******************************************


if($query)
{
    $_image_upload_list_to_check =
        ['icon',
            'image1','image2','image3','image4','image5',
            'image6','image7','image8','image9','image10',
            'video', 'banner', 'attachment', 'extend_img'];

//循环判断检查所有要上传的图片，去做移动
    foreach ($_image_upload_list_to_check as $value)
    {
        if(isset($_REQUEST['ai_'.$value]))
        {

            $source      = ROOT_PATH_ . "/uploadfiles/temp/".$_REQUEST['ai_'.$value];
            $destination = ROOT_PATH_ . "/uploadfiles/".$_REQUEST['ai_'.$value];

            if (file_exists($source))
            {
                if (copy($source, $destination))
                {
                    unlink($source); // 删除源文件
                }
                else
                {
                    error_log("Failed to copy file from $source to $destination");
                }
            }



        }
    }
}
//******************************************
//判断是否插入成功，然后把图片从temp目录移动出来
//******************************************






?>

